package ws.very.common.web.views
import ws.very.util.lang.{ Texts => Ts }
object Texts {
  def highLight(txt: S, wordGroup: Iterable[S]) = {
    (txt /: wordGroup) {
      case (txt, w) =>
        s"(?i)$w".r.replaceAllIn(txt, { m =>
          s"<em>${m.matched}</em>"
        })
    }
  }
  def split2Word(s: S) =
    Option(s).map { _.split(Ts.Regex.UniCode.butWord).filter(_.trim().nonEmpty).distinct }

  def highLightFn(s: S) = {
    split2Word(s).map { group =>
      txt: S => highLight(txt, wordGroup = group)
    }.getOrElse { txt: S => txt }
  }
}